package com.ruoyi.web.controller.fx;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.fx.FxAppointment;
import com.ruoyi.system.domain.vo.FxAppointmentVo;
import com.ruoyi.system.service.fx.IFxAppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 服务预约
 *
 * @author ruoyi
 * @date 2025-04-29
 */
@RestController
@RequestMapping("/system/appointment")
public class FxAppointmentController extends BaseController
{
    @Autowired
    private IFxAppointmentService fxAppointmentService;

    /**
     * 查询服务预约列表
     * @return {@link FxAppointment}
     */
    @GetMapping("/list")
    public TableDataInfo list(FxAppointment fxAppointment)
    {
        startPage();
        List<FxAppointment> list = fxAppointmentService.selectFxAppointmentList(fxAppointment);
        return getDataTable(list);
    }

    /**
     * 导出服务预约列表
     */
    @Log(title = "服务预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FxAppointment fxAppointment)
    {
        List<FxAppointment> list = fxAppointmentService.selectFxAppointmentList(fxAppointment);
        ExcelUtil<FxAppointment> util = new ExcelUtil<FxAppointment>(FxAppointment.class);
        util.exportExcel(response, list, "服务预约数据");
    }

    /**
     * 获取服务预约详细信息
     * @return {@link FxAppointmentVo}
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fxAppointmentService.selectFxAppointmentById(id));
    }

    /**
     * 新增服务预约
     */
    @Log(title = "服务预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FxAppointment fxAppointment)
    {
        return success(fxAppointmentService.insertFxAppointment(fxAppointment));
    }

    /**
     * 修改服务预约
     */
    @Log(title = "服务预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FxAppointment fxAppointment)
    {
        return toAjax(fxAppointmentService.updateFxAppointment(fxAppointment));
    }

    /**
     * 删除服务预约
     */
    @Log(title = "服务预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fxAppointmentService.deleteFxAppointmentByIds(ids));
    }

    /**
     * 预约单支付
     */
    @GetMapping("/pay")
    public AjaxResult pay(String orderId)
    {
        return success(fxAppointmentService.pay(orderId));
    }


    /**
     * 预约单支付回调
     */
    @PostMapping("/payNotify")
    public AjaxResult payNotify(HttpServletRequest request, HttpServletResponse response) {
        return success(fxAppointmentService.payNotify(request, response));
    }

    /**
     * 退单
     */
    @GetMapping("/chargebackOrder")
    public AjaxResult chargebackOrder( String orderId){
        return success(fxAppointmentService.chargebackOrder(orderId));
    }



}
